package com.expense.services;

import java.util.Date;
import java.sql.ResultSet;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.expense.dao.Dao;
import com.expense.entity.MessageInfo;
import com.expense.entity.UserInfo;
import com.expense.util.PaginatedList;

public class MessageServices extends BasicServices {
	
	/**
	 * 添加一条消息
	 * */
	public int add(Integer receiverUId,String subject,String content,Date sendTime,int messageType,Boolean hasRead){
		MessageInfo modMessage=new MessageInfo();
		modMessage.setReceiveruid(receiverUId);
		modMessage.setSubject(subject);
		modMessage.setContent(content);
		modMessage.setSendTime(sendTime);
		modMessage.setMessageType(messageType);
		modMessage.setHasRead(hasRead);	
		
		return this.addObjectInfo(modMessage);
	}

	/**
	 * 删除一条消息
	 * */
	public Boolean delete(Integer mmid){
		
		return this.deleteObjectById(mmid, MessageInfo.class);
	}

	/**
	 * 查询个人消息
	 * */
	public List getMessagesByUID(Integer uid,int pageSize ,int currentPage,String whereSql,String orderSql){
		Dao dao=new Dao();
		PaginatedList paginatedList=null;
		if (dao.getConn()!=null) {
			String tableName=this.getTableName(MessageInfo.class);
			
		String sql="select * from "+tableName+" where "+whereSql+" "+orderSql;
		System.out.println(sql);
		paginatedList= dao.paginatedListData(pageSize, currentPage, tableName, whereSql, orderSql);
		}
		dao.CloseCon();//关闭此次连接
		return paginatedList!=null?paginatedList.getDataList():null;
	}
}
